﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinQ_DTO;

namespace DAO
{
    public class LoaiSanPhamDAO
    {
        public List<shop_loaisanpham> LayLoaiSanPham()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var ProductTypes = from c in EFashionDB.shop_loaisanphams select c;
            return ProductTypes.ToList();
        }

       

       
        public shop_loaisanpham LayLoaiSanPhamTheoMa(int MaLoai)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_loaisanpham select = EFashionDB.shop_loaisanphams.Single(c => c.MaLoaiSanPham == MaLoai);
            return select;
        }

        public void ThemLoaiSanPham(shop_loaisanpham a)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            EFashionDB.shop_loaisanphams.InsertOnSubmit(a);
            EFashionDB.SubmitChanges();

        }

        public void XoaLoaiSanPhamTheoMa(int MaLoai)
        {

            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var List = from a in EFashionDB.shop_loaisanphams
                       where a.MaLoaiSanPham == MaLoai
                       select a;
            shop_loaisanpham ResultCmt = List.Single();
            EFashionDB.shop_loaisanphams.DeleteOnSubmit(ResultCmt);
            EFashionDB.SubmitChanges();

        }

        public void CapNhatSP(shop_loaisanpham a)
        {

            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            shop_loaisanpham select = EFashionDB.shop_loaisanphams.Single(c => c.MaLoaiSanPham == a.MaLoaiSanPham);
            if (select != null)
            {
                select.TenLoaiSanPham = a.TenLoaiSanPham;
            }
            EFashionDB.SubmitChanges();
        }
/////////////////////////////////////////////////////////////////////////////////////////////
        /************************************************************************************************************        *                          coder: TRAN KINH LY 
         ***********************************************************************************************************/

        public List<shop_loaisanpham> layLoaiSanPhamGioiHan(int iStart, int iLimit)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var ProductTypes = (from c in EFashionDB.shop_loaisanphams
                                select c).Skip(iStart).Take(iLimit);
            return ProductTypes.ToList();
        }

        public int laySoLuongLoaiSanPham()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            int totalrow = EFashionDB.shop_loaisanphams.Count();
            return totalrow;
        }

        public List<shop_loaisanpham> LayLoaiSanPhamTheoKhoa(String key_search)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var ProductTypes = from c in EFashionDB.shop_loaisanphams
                               where c.TenLoaiSanPham.Contains(key_search)
                               select c;
            return ProductTypes.ToList();
        }


        /************************************************************************************************************        *                          coder: TRAN KINH LY 
         ***********************************************************************************************************/


    }
}
